package com.zyf.workflow.test.work;

import com.zyf.workflow.business.fwupgrade.FwUpgradeBean;
import com.zyf.workflow.business.fwupgrade.PackageWorker;
import com.zyf.workflow.node.Node;
import com.zyf.workflow.node.WorkNode;
import com.zyf.workflow.node.bean.NodeType;
import com.zyf.workflow.work.AbstractWork;
import com.zyf.workflow.work.bean.WorkTypeEnum;
import com.zyf.workflow.worker.Worker;

import java.util.ArrayList;
import java.util.List;

public class OutBandUpgradeWork<T> extends AbstractWork<List<FwUpgradeBean>> {

    public OutBandUpgradeWork(List<FwUpgradeBean> data, String workName) {
        super(data, workName);
    }

    private Node<String> outBandUpgrade(List<FwUpgradeBean> fwUpgradeBeans) {
        PackageWorker packageWorker = new PackageWorker();
        Worker<List<FwUpgradeBean>, String, Void> worker = packageWorker::outBandUpgrade;

        return new WorkNode.Builder<List<FwUpgradeBean>, String>()
                .withWorker(worker)
                .withNodeId(1)
                .withData(fwUpgradeBeans)
                .withName("outband")
                .setCallBack((data, param) -> {
                    System.out.println("fwUpgrade node finished");
                    System.out.println(".....");
                })
                .withType(NodeType.WORK)
                .create();
    }

    @Override
    public List<Node<?>> initNodes(List<FwUpgradeBean> data) {
        List<FwUpgradeBean> fwUpgradeBeanList = (List<FwUpgradeBean>) data;

        List<Node<?>> nodes = new ArrayList<>();
        Node<String> packageNode = outBandUpgrade(fwUpgradeBeanList);

        nodes.add(packageNode);

        return nodes;
    }

    @Override
    public WorkTypeEnum getWorkType() {
        return WorkTypeEnum.WORK;
    }
}
